package com.example.myapplication.data

import android.content.Context
import com.example.myapplication.bean.User
import com.ftw.commons.BuildConfig.BASE_URL
import com.ftw.commons.bean.Response
import com.ftw.commons.network.NetworkUtils
import io.reactivex.Observable


/**
 * 描    述：
 * 作    者：fantianwen
 * 时    间：2019/4/18  5:52 PM
 *
 */


object MailRepo {


    @Volatile
    private var mService: MailService? = null

    private fun getService(context: Context): MailService =
        mService ?: synchronized(this) {
            mService ?: NetworkUtils.initRetrofit(
                BASE_URL, context
            ).create(MailService::class.java)
        }


    /**
     * 执行登陆
     */
    fun login(
        context: Context, userRequest: LoginRequest
    ): Observable<Response<User>> {
        return getService(context)
            .login(userRequest)
    }


}